package com.hfuuTaf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hfuuTaf.mapper.registerMapper;
import com.hfuuTaf.pojo.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@Controller
public class safeController {
    private final registerMapper registerMapper;
    public safeController(com.hfuuTaf.mapper.registerMapper registerMapper) {
        this.registerMapper = registerMapper;
    }

    @RequestMapping("/hfuuTaf/login")
    public String tafLogin() {
        return "login";
    }

    /***
     * 第一是详细,第二个是列表
     */
    @RequestMapping("/hfuuTaf/VivaDetail")
    public String tafMainDetail(Model model,@RequestParam(value = "id") int id){
        QueryWrapper<register> wrapperOne = new QueryWrapper<register>().eq("id", id);
        register register = registerMapper.selectOne(wrapperOne);
        model.addAttribute("register",register);
        return "userDetail";

    }



    @RequestMapping("/hfuuTaf/Viva")
    public String tafMain(Model model,@RequestParam(value = "pageNow", defaultValue = "1") int pageNow) {
        QueryWrapper<register> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("date");
        Page<register> page = new Page<>(pageNow, 10);
        Page<register> registerPage = registerMapper.selectPage(page,wrapper);
        List<register> registers = registerPage.getRecords();
        model.addAttribute("registers",registers);//表格

        long countAll = registerMapper.selectCount(null);
        int pageAll = (int) Math.floor(countAll / 10);
        pageAll++;
        model.addAttribute("countAll", countAll);
        model.addAttribute("pageNow", pageNow);
        model.addAttribute("pageAll", pageAll);

        return "userList";
    }
}
